package com.maoxs;

import com.maoxs.filter.TestFilter;
import com.maoxs.listener.TestListener;
import com.maoxs.servlet.TestServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
//扫描对应包下的
@ServletComponentScan("com.maoxs")
public class SpringbootWebApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootWebApplication.class, args);
    }

    //   //在springboot使用springmvc 的时候不需要配置DispatcherServlet的因为已经自动配置了
//   //但是如果想要加一些初始配置参数如何解决呢，添加以下代码即可。
//    @Bean
//    public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {
//        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
//        registration.addUrlMappings("*.do");
//        registration.addUrlMappings("*.json");
//        return registration;
//    }
    /******************使用bean注册的形式注册**********************/
//    @Bean
//    public ServletRegistrationBean servletRegistrationBean() {
//        return new ServletRegistrationBean(new TestServlet(), "/show/*");// ServletName默认值为首字母小写，即myServlet
//    }
//    @Bean
//    public FilterRegistrationBean indexFilterRegistration() {
//        FilterRegistrationBean registration = new FilterRegistrationBean(new TestFilter());
//        registration.addUrlPatterns("/");
//        return registration;
//    }
//    @Bean
//    public ServletListenerRegistrationBean servletListenerRegistrationBean(){
//        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
//        servletListenerRegistrationBean.setListener(new TestListener());
//        return servletListenerRegistrationBean;
//    }
}
